﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Lead2012.Business
{
    public class NotificationResponseLogRepository
    {
        // Create an instance of entities framework
        Lead2012Entities entities = new Lead2012Entities();

        public int GetLeadId(int userId)
        {
            var item = (from c in entities.NotificationResponseLogs
                        where c.UserId == userId && c.Response == false
                        orderby c.LogId descending
                        select c).FirstOrDefault();

            if (item != null)
                return item.LeadId;

            return 0;
        }

        public NotificationResponseLog GetSingleByLeadId(int id)
        {
            return (from c in entities.NotificationResponseLogs
                    where c.LeadId == id && c.Response == false
                    select c).FirstOrDefault();
        }

        public NotificationResponseLog GetSingle(int id)
        {
            return (from c in entities.NotificationResponseLogs where c.LogId == id select c).FirstOrDefault();
        }
        public void Create(NotificationResponseLog _object)
        {
            entities.AddToNotificationResponseLogs(_object);
            entities.SaveChanges();
        }
        public void Update(NotificationResponseLog _object)
        {
            entities.SaveChanges();
        }
        public void Delete(int id)
        {
            var _object = (from _list in entities.NotificationResponseLogs where _list.LogId == id select _list).First();
            entities.DeleteObject(_object);
            entities.SaveChanges();
        }
    }
}